<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发送消息测试</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h2>发送消息测试</h2>
        
        <div class="card">
            <div class="card-header">
                <h5>发送带跳转链接的消息</h5>
            </div>
            <div class="card-body">
                <form id="messageForm">
                    <div class="mb-3">
                        <label for="userId" class="form-label">用户ID</label>
                        <input type="number" class="form-control" id="userId" value="1" required>
                    </div>
                    <div class="mb-3">
                        <label for="title" class="form-label">消息标题</label>
                        <input type="text" class="form-control" id="title" value="测试消息" required>
                    </div>
                    <div class="mb-3">
                        <label for="content" class="form-label">消息内容</label>
                        <textarea class="form-control" id="content" rows="3" required>这是一条带跳转链接的测试消息</textarea>
                    </div>
                    <div class="mb-3">
                        <label for="redirectUrl" class="form-label">跳转链接</label>
                        <input type="text" class="form-control" id="redirectUrl" value="/test-entity-change-detailed.html">
                        <div class="form-text">留空则不设置跳转链接</div>
                    </div>
                    <button type="submit" class="btn btn-primary">发送消息</button>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script>
        // 处理表单提交
        $('#messageForm').submit(function(e) {
            e.preventDefault();
            
            const userId = $('#userId').val();
            const title = $('#title').val();
            const content = $('#content').val();
            const redirectUrl = $('#redirectUrl').val();
            
            // 构造请求数据
            const requestData = {
                receiverUserId: userId,
                title: title,
                content: content,
                type: 1,
                important: 0,
                redirectUrl: redirectUrl || null
            };
            
            // 发送消息
            $.ajax({
                url: '/test/sendMessage',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(requestData),
                success: function(response) {
                    if (response.code === 0) {
                        alert('消息发送成功');
                        $('#messageForm')[0].reset();
                    } else {
                        alert('消息发送失败: ' + response.msg);
                    }
                },
                error: function() {
                    alert('请求失败，请检查网络连接');
                }
            });
        });
    </script>
</body>
</html>